<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
$sPage = $_REQUEST["page"];
$sID = $_REQUEST["ID"];
$sDefType = $_REQUEST['defType'];

$aTypes = $RoleAdmin->GetRoleDefinitionTypes();
$aTypeLinks = array();
foreach($aTypes as $sType)
{
    $aTypeLinks[] = "<a href=\"{$_SERVER["PHP_SELF"]}?page=$sPage&amp;ID=$sID&amp;defType=$sType\">$sType</a>";
    
}
$sType = join(", ", $aTypeLinks);
?>

<p><a href="<?=$_SERVER["PHP_SELF"];?>?page=listrole">List Roles</a> | <a href="<?=$_SERVER["PHP_SELF"];?>?page=editrolebatch">Batch Add Roles</a></p>

<form method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<table border="0" cellpadding="0" cellspacing="0" class="app_table">
<tr class="app_row">
    <td>
	<b>Role Type</b>
    </td>
    <td>
	<select name="roleTypeID" size="1" class="app_select">
	<?
        $aTypes=$RoleAdmin->GetRoleTypes();
        for ($i=0; $i<count($aTypes); $i++)
        {
	    if ($aTypes[$i]["ID"]==$aInfo["roleTypeID"])
	    {
		$s=" selected";
	    }
	    else
	    {
		$s="";
	    }
            ?>
            <option value="<?=$aTypes[$i]["ID"];?>"<?=$s;?>><?=$aTypes[$i]["name"];?></option>
            <?
        }
        ?>
	</select>
    </td>
</tr>
<tr class="app_row">
    <td>
    <b>Role Name <br/>(Role Definition String)</b>
    </td>
    <td>
	<input type="text" name="roleDefinitionString" value="" size="30" class="app_textinput">
	<br>(Required if not specifying an existing Role Definition.)
    </td>
</tr>
<tr class="app_row">
    <td>
	<b>Role Definition Description</b>
    </td>
    <td>
	<select name="roleDefinitionDescription" size="1" class="app_select">
	<?
        $aTypes=$RoleAdmin->GetRoleDefinitionTypes();
        for ($i=0; $i<count($aTypes); $i++)
        {
            ?>
	    <option value="<?=$aTypes[$i];?>"><?=$aTypes[$i];?></option>
            <?
        }
        ?>
	</select>
	<br>(Required if not specifying an existing Role Definition.)
    </td>
</tr>
<tr class="app_row">
    <td>
	<b>Existing Role Definition</b>
    </td>
    <td>

    <?=$sType?>
	
    <?
	if ($sDefType || $aInfo["roleDefinitionType"] != "")
	{
	    if($sDefType)
	    {
		$sUseType=$sDefType;
	    }
	    elseif($aInfo["roleDefinitionType"] != "")
	    {
		$sUseType = $aInfo["roleDefinitionType"];
	    }
	    $aRoleDefinitions = $RoleAdmin->GetRoleDefinitionsByType($sUseType);
	    ?>
    
	    <select name="roleDefinitionID" size="1" class="app_select">
		<option value=""></option>
		<?
		foreach($aRoleDefinitions as $aRoleDefinition)
		{
		    $nID = $aRoleDefinition["ID"];
		    $sName = $aRoleDefinition["name"];

		    $sSelected = "";
		    if ($nID == $aInfo["roleDefinitionID"])
		    {
			$sSelected = " selected";
		    }
		    ?>
		    <option value="<?=$nID?>"<?=$sSelected?>><?=$sName?></option>
		    <?
		}
		?>
	    </select>
        <?
	}
	else
	{
	    //echo "<br>Select Definition Type: <b>$sDefType</b>";
	}
    
	
	?>
    <br/>(Will be overridden by Role Name/Definition if specified above.)
	
    </td>
</tr>
<tr class="app_row">
    <td>
	<b>Role String ID (optional)</b>
    </td>
    <td>
	<input type="text" name="roleStringID" value="<?=$aInfo["roleStringID"];?>" size="30" class="app_textinput">
    </td>
</tr>
<tr class="app_row">
    <td>
	<b>Notes (optional)</b>
    </td>
    <td>
	<input type="text" name="notes" value="<?=$aInfo["notes"];?>" size="30" class="app_textinput">
    </td>
</tr>
<tr class="app_row">
    <td colspan="2">
	<input type="hidden" name="roleID" value="<?=$aInfo["ID"];?>">
	<input type="hidden" name="page" value="setrole">
	<input type="submit" name="submit" value="Submit" class="app_submit">
    </td>
</tr>
</table>
</form>


